﻿ INSERT INTO ICC_ABAUFM(ABAID,ABAMANDANT,ABAAUFTYP,ABAERLKZ,ABARESMG, ABAQTYALLOCATE,ABAQTYRESERVE,ABAQTYRECEIVED,ABAVKAUFTYP, ABAVKAUFKRS, ABAVKAUFLFD, ABAVKAUFPOS, ABAVKUPOS,ABAART,ABAVAR,ABAFARBE,ABAGROE)
  SELECT SEQ_ICC_MU.NEXTVAL,R.MDMANDANT,'N','N',R.MDMENGE,0,0,0,R.MDTYP,R.MDAUFKRS,R.MDAUFLFD,R.MDAUFPOS,R.MDRPOS,substr(mdmat||'                ',1,20),R.MDVAR,substr( '                    ',1,10),substr( '                    ',1,7) FROM MDECK R
 WHERE NOT EXISTS 
 (SELECT 1 FROM ICC_ABAUFM M  WHERE R.MDAUFKRS=M.ABAVKAUFKRS AND R.MDAUFLFD=M.ABAVKAUFLFD AND R.MDAUFPOS=M.ABAVKAUFPOS AND TRIM(R.MDRPOS)=TRIM(M.ABAVKUPOS))
 GO
 INSERT INTO ICC_ABAUFM(ABAID,ABAMANDANT,ABAAUFTYP,ABAERLKZ,ABARESMG,ABAQTYALLOCATE,ABAQTYRESERVE,ABAQTYRECEIVED, ABAVKAUFTYP, ABAVKAUFKRS, ABAVKAUFLFD, ABAVKAUFPOS, ABAVKUPOS,ABAART,ABAVAR,ABAFARBE,ABAGROE)
  SELECT SEQ_ICC_MU.NEXTVAL,R.WDMANDANT,'N','N',R.WDBEDARF,0,0,0,R.WDTYP,R.WDAUFKRS,R.WDAUFLFD,R.WDAUFPOS,R.WDUPOS,WDART,WDVAR,WDFARBE,substr( '                    ',1,7) FROM WDECK R 
WHERE NOT EXISTS 
 (SELECT 1 FROM ICC_ABAUFM M  WHERE R.WDAUFKRS=M.ABAVKAUFKRS AND R.WDAUFLFD=M.ABAVKAUFLFD AND R.WDAUFPOS=M.ABAVKAUFPOS AND TRIM(R.WDUPOS)=TRIM(M.ABAVKUPOS))
 GO
INSERT INTO ICC_ABAUFM(ABAID,ABAMANDANT,ABAAUFTYP,ABAERLKZ,ABARESMG,ABAQTYALLOCATE,ABAQTYRESERVE,ABAQTYRECEIVED, ABAVKAUFTYP, ABAVKAUFKRS, ABAVKAUFLFD, ABAVKAUFPOS, ABAVKUPOS,ABAART,ABAVAR,ABAFARBE,ABAGROE)
  SELECT SEQ_ICC_MU.NEXTVAL,R.FDMANDANT,'N','N',R.FDMENGE,0,0,0,R.FDTYP,R.FDAUFKRS,R.FDAUFLFD,R.FDAUFPOS,SUBSTR(R.FDSETPOS,2,2),FDART,FDVAR,FDFARBE,FDGROE FROM FDECK R 
  WHERE NOT EXISTS
 (SELECT 1 FROM ICC_ABAUFM M  WHERE R.FDAUFKRS=M.ABAVKAUFKRS AND R.FDAUFLFD=M.ABAVKAUFLFD AND R.FDAUFPOS=M.ABAVKAUFPOS AND TRIM(SUBSTR(R.FDSETPOS,2,2))=TRIM(M.ABAVKUPOS))
GO
 INSERT INTO ICC_ABAUFM(ABAID,ABAMANDANT,ABAAUFTYP,ABAERLKZ,ABARESMG,ABAQTYALLOCATE,ABAQTYRESERVE,ABAQTYRECEIVED, ABAVKAUFTYP, ABAVKAUFKRS, ABAVKAUFLFD, ABAVKAUFPOS, ABAVKUPOS,ABAART,ABAVAR,ABAFARBE,ABAGROE)
 SELECT SEQ_ICC_MU.NEXTVAL,R.GAMANDANT,'N','N',R.GAKG1,0,0,0,'V',R.GAAUFKRS,R.GAAUFLFD,R.GAAUFPOS,R.GAPOS,GAART,GAVAR,GAFARBE,substr( '                    ',1,7) FROM GAAUF R 
  WHERE NOT EXISTS
 (SELECT 1 FROM ICC_ABAUFM M  WHERE R.GAAUFKRS=M.ABAVKAUFKRS AND R.GAAUFLFD=M.ABAVKAUFLFD AND R.GAAUFPOS=M.ABAVKAUFPOS AND TRIM(R.GAPOS)=TRIM(M.ABAVKUPOS))
GO